package util;

import javax.servlet.http.HttpServletRequest;

public class Tools {
	
	//过滤HTML函数
	public static String filterHTML(String html){
		return html;
	}
	
	//判断分页数
	public static Integer checkPage(String page){
		Integer res = null;
		if(page.equals(null)||page.equals("")){
			res = 1;
		}else{
			res = new Integer(page);
		}
		return res;
	}
	
	public static String changeEncoding(String str) throws Exception{
		return new String(str.getBytes("iso-8859-1"),"utf-8");
	}
	
	//获得IP地址
	public static String getIpAddr(HttpServletRequest request) { 
	    String ip = request.getHeader("x-forwarded-for"); 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getHeader("Proxy-Client-IP"); 
	    } 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getHeader("WL-Proxy-Client-IP"); 
	    } 
	    if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) { 
	        ip = request.getRemoteAddr(); 
	    } 
	    return ip; 
	}
	
}
